package com.dog.modules.file.web;

import com.dog.framework.core.model.ResponseResult;
import com.dog.modules.file.model.SysFileUploadVO;
import com.dog.modules.file.service.OssService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 用户信息
 *
 * @author liuxk
 */
@Slf4j
@RestController
@RequestMapping("/file")
@Tag(name = "文件上传")
@AllArgsConstructor
public class FileController {


    private final OssService ossService;


    @PostMapping("/upload")
    @Operation(summary = "文件上传")
    public ResponseResult<SysFileUploadVO> uploadFile(@Parameter(name = "表单文件对象") @RequestParam(value = "file") MultipartFile file) {
        SysFileUploadVO fileInfo = ossService.uploadFile(file);
        return ResponseResult.success(fileInfo);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "文件删除")
    public ResponseResult deleteFile(@Parameter(name = "文件路径") @RequestParam String fileUrl) {
        boolean result = ossService.deleteFile(fileUrl);
        return ResponseResult.judge(result);
    }


}
